package com.qingcheng.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.qingcheng.pojo.seckill.SeckillGood;
import com.qingcheng.service.seckill.SeckillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yuanxin
 * Date:2019/7/22
 * Time:15:55
 */
@Service
public class SeckillGoodsServiceImpl implements SeckillGoodsService {
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * Redis中根据Key获取秒杀商品列表
     * @param time
     * @return
     */
    @Override
    public List<SeckillGood> list(String time) {
        String key = "SeckillGoods_"+time;
        List<SeckillGood> seckillGoods = redisTemplate.boundHashOps(key).values();
        return seckillGoods!=null?seckillGoods:new ArrayList<>();
    }

    @Override
    public SeckillGood one(String time, Long id) {
        String key = "SeckillGoods_"+time;
        return (SeckillGood) redisTemplate.boundHashOps(key).get(id);
    }
}
